package com.example.spring_mybatis.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.spring_mybatis.dto.UserDTO;
import com.example.spring_mybatis.mapper.UserMapper;
import com.example.spring_mybatis.model.UserEntity;
import com.example.spring_mybatis.service.IUserService;
import com.example.spring_mybatis.utils.RUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public RUtil<String> createUser(UserDTO userDto) {
        UserEntity userEntity = new UserEntity();
        BeanUtils.copyProperties(userDto, userEntity);
        int insert = this.userMapper.insert(userEntity);
        if (insert == 1) {
            return RUtil.success("创建成功");
        } else {
            return RUtil.error("创建失败");
        }
    }
}
